package net.bwie.realtime.vehicle.mapper;

import net.bwie.realtime.vehicle.bean.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: fh
 * @Date: 2025/5/27
 */
@Mapper
public interface VehicleRealtimeMapper {
    @Select("select vin_count as UvCount from vehicle_report.vehicle_count order by window_start desc limit 1")
    Double selectUvCount(@Param("date") String date);

    @Select("select vin_health as UvCount from vehicle_report.vehicle_health order by window_start desc limit 1")
    Double selectHealth(String date);

    @Select("select province AS name,vin_count AS `value` from vehicle_report.vehicle_province_count_report")
    List<VehicleProvinceCount> selectProvinceCount(String date);

    @Select("select alarm_type as name,count(*) as value from vehicle_report.vehicle_abnormal_alarm group by alarm_type")
    List<VehicleProvinceCount> selectAlarm(String date);

    @Select("select vin,distance,duration as drivingDuration,vgSpeed as avgSpeed,maxSpeed as maxSpeed," +
            "if(speeding='true','已超速','未超速') as speeding from vehicle_report.dws_itineraryanalysis")
    List<VehicleTrip> selectTrip(String date);

    @Select("select vin,speed,battery_level as batteryLevel,battery_temp as batteryTemp,motor_temp as motorTemp," +
            "charging_status as chargingStatus,energy_consumption as energyConsumption " +
            "from vehicle_report.vehicle_condition_monitoring")
    List<VehicleStatus> selectStatus(String date);

    @Select("select vin,alarm_type as alarmType from vehicle_report.vehicle_abnormal_alarm")
    List<VehicleAlarm> selectAlarm2(String date);

    @Select("select vin name,avg(speed) value from vehicle_report.vehicle_condition_monitoring group by vin ")
    List<VehicleVinSpeed> selectVinSpeed(String date);

    @Select("select vin name,distance value from vehicle_report.dws_itineraryanalysis")
    List<VehicleVinSpeed> selectVinDistance(String date);

    @Select("select toDate(window_start) AS name,vin_health AS value from vehicle_report.vehicle_health")
    List<SugarOne> selectVinHealth(String date);
}
